﻿using System;
using System.Collections.Generic;
using STeaL.Functional;

namespace STeaL.Algorithm {
  public static partial class IListExtensions {
#region iter_swap
    public static void iter_swap<T>(this IList<T> list, int x, int y) {
      T tmp = list[x]; list[x] = list[y]; list[y] = tmp;
    }

#endregion
#region reverse
    public static void reverse<T>(this IList<T> list, int first, int last) {
      while ( first < --last ) {
        iter_swap(list, first, last);
        ++first;
      }
    }

    public static void reverse<T>(this IList<T> list) {
      reverse(list, 0, list.Count);
    }

#endregion
  }
}
